
//引入网络库
import { get, post } from "../../util/util.js"
// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "fabuxinju",
  /**
   * 页面的初始数据
   */

  data: {
    fid: '',
    uid: '1',
    itemId: 0,
    itemsRoles: [],
    headerImg: '',//剧组海报
    bgImg: '',//剧组海报
    //输入内容
    filmName: '',
    address: '',
    zhouqi: '',
    zhipian: '',
    daoyan: '',
    tongchou: '',
    zhuli: '',
    zhixing: '',
    phone: '',
    wxStr: '',
    email: '',
    //时间选择
    shangying: '0000-00-00',
    kaishi: '0000-00-00',
    jieshu: '0000-00-00',
    //简介
    jianjie: '',
    //影片题材
    currentItemYptc: '',
    yptcList: [],
    yptcKey: '',
    yptcArr: [],
    //播出平台
    currentItemBcpt: '',
    bcptList: [],
    bcptKey: '',
    bcptArr: [],
    //年纪   
    currentItemAge_group: '',
    age_groupList: [],
    age_groupKey: null,
    age_groupArr: [],
    //颜值
    currentItemFace_group: '',
    face_groupList: [],
    face_groupKey: null,
    face_groupArr: [],
    //特长 
    feature_groupList: [],
    feature_groupArr: [],
    feature_groupSize: 1,
    //shengao
    currentItemHeight_group: '',
    height_groupList: [],
    height_groupKey: null,
    height_groupArr: [],
    //角色类型
    currentItemRole_type: '',
    role_typeList: [],
    role_typeKey: null,
    role_typeArr: [],
    //性别
    currentItemSex: '',
    sexList: [],
    sexKey: null,
    sexArr: [],
    //体型
    currentItemShape_group: '',
    shape_groupList: [],
    shape_groupKey: null,
    shape_groupArr: [],
    //特征 
    // skill_group: [],
    skill_groupList: [],
    skill_groupArr: [],

    // skill_group1:[],
    skill_groupList1: [],
    skill_groupSize1: 1,
    skill_groupArr1: [],

    // skill_group2: [],
    skill_groupList2: [],
    skill_groupSize2: 1,
    skill_groupArr2: [],
    //语言 
    languageList: [],
    languageArr: [],
    languageSize: 1,
    //性别
    currentItemSex: '',
    sexList: [],
    sexKey: null,
    sexArr: [],
    ///======
    //角色===
    juesemingStr: '',
    zhuanjiStr: '',
    jueseStr: '',
    nianlingStr: '',
    jslxArr: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  onLoad: function (o) {
    var that = this;
    console.log("新增新剧===uid===" + o.uid);
    var imageitem;
    var imageitemstring = '';
    imageitem = '{' + '"id":"' + '' + '",' +
      '"name":"' + '' + '",' +
      '"role_type":' + null + ',' +
      '"age_group":' + null + ',' +
      '"face_group":' + null + ',' +
      '"feature_group":' + null + ',' +
      '"sex":' + 1 + ',' +
      '"biography":"' + '' + '",' +
      '"others":"' + '' + '",' +
      '"height_group":' + null + ',' +
      '"shape_group":' + null + ',' +
      '"skill_group":' + null + ',' +
      '"language":' + null + '}';

    imageitemstring += imageitem
    var imageList = '{"roles":[' + imageitemstring + ']}';

    that.setData({
      uid: o.uid,
      itemsRoles: JSON.parse(imageList).roles,
    })
    console.log("itemsRoles=-====" + JSON.stringify(that.data.itemsRoles));
    //------film/createconf-----------配置数据获取---------------------//影片类型配置
    //艺人配置
    post("/tag/getConfig", {}).then(data => {
      //语言  
      var languageData = [];
      var languageStr = [];
      for (var key in data.data.language) {
        languageData.push(key);
        languageStr.push(data.data.language[key]);
      }
      var languageJson = [];
      for (var i = 0; i < languageStr.length; i++) {
        var j = {};
        j.val = languageData[i];
        j.name = languageStr[i];
        j.value = i;
        j.checked = false;
        languageJson.push(j);
      }
      that.setData({
        languageList: languageData,
        languageArr: languageJson,
      })

      //性别 
      var sexData = [];
      var sexStr = [];
      for (var key in data.data.sex) {
        sexData.push(key);
        sexStr.push(data.data.sex[key]);
      }
      that.setData({
        sexList: sexData,
        sexArr: sexStr,
      })
    })
    post("/film/createconf", {}).then(data => {
      //影片类型 
      var yptcData = [];
      var yptcStr = [];
      for (var key in data.data.subject) {
        yptcData.push(key);
        yptcStr.push(data.data.subject[key]);
      }

      var bcptData = [];
      var bcptStr = [];
      for (var key in data.data.play_platform) {
        bcptData.push(key);
        bcptStr.push(data.data.play_platform[key]);
      }

      var age_groupData = [];
      var age_groupStr = [];
      for (var key in data.data.age_group) {
        age_groupData.push(key);
        age_groupStr.push(data.data.age_group[key]);
      }

      var face_groupData = [];
      var face_groupStr = [];
      for (var key in data.data.face_group) {
        face_groupData.push(key);
        face_groupStr.push(data.data.face_group[key]);
      }

      var feature_groupData = [];
      var feature_groupStr = [];
      for (var key in data.data.feature_group) {
        feature_groupData.push(key);
        feature_groupStr.push(data.data.feature_group[key]);
      }
      var featureJson = [];
      for (var i = 0; i < feature_groupStr.length; i++) {
        var j = {};
        j.val = feature_groupData[i];
        j.name = feature_groupStr[i];
        j.value = i;
        j.checked = false;
        featureJson.push(j);
      }


      var height_groupData = [];
      var height_groupStr = [];
      for (var key in data.data.height_group) {
        height_groupData.push(key);
        height_groupStr.push(data.data.height_group[key]);
      }

      var role_typeData = [];
      var role_typeStr = [];
      for (var key in data.data.role_type) {
        role_typeData.push(key);
        role_typeStr.push(data.data.role_type[key]);
      }

      var sexData = [];
      var sexStr = [];
      for (var key in data.data.sex) {
        sexData.push(key);
        sexStr.push(data.data.sex[key]);
      }

      var shape_groupData = [];
      var shape_groupStr = [];
      for (var key in data.data.shape_group) {
        shape_groupData.push(key);
        shape_groupStr.push(data.data.shape_group[key]);
      }

      var skill_groupData1 = [];
      var skill_groupStr1 = [];
      // for (var key in data.data.skill_group) {
      for (var keyItem in data.data.skill_group[1]) {
        skill_groupData1.push(keyItem);
        skill_groupStr1.push(data.data.skill_group[1][keyItem]);
      }
      // }

      var skill_groupJson1 = [];
      for (var i = 0; i < skill_groupStr1.length; i++) {
        var j = {};
        j.val = skill_groupData1[i];
        j.name = skill_groupStr1[i];
        j.value = i;
        j.checked = false;
        skill_groupJson1.push(j);
      }

      //======================
      var skill_groupData2 = [];
      var skill_groupStr2 = [];
      // for (var key in data.data.skill_group) {
      for (var keyItem in data.data.skill_group[2]) {
        skill_groupData2.push(keyItem);
        skill_groupStr2.push(data.data.skill_group[2][keyItem]);
      }
      // }

      var skill_groupJson2 = [];
      for (var i = 0; i < skill_groupStr2.length; i++) {
        var j = {};
        j.val = skill_groupData2[i];
        j.name = skill_groupStr2[i];
        j.value = i;
        j.checked = false;
        skill_groupJson2.push(j);
      }


      that.setData({
        yptcList: yptcData,
        yptcArr: yptcStr,

        bcptList: bcptData,
        bcptArr: bcptStr,

        age_groupList: age_groupData,
        age_groupArr: age_groupStr,

        face_groupList: face_groupData,
        face_groupArr: face_groupStr,

        feature_groupList: feature_groupData,
        feature_groupArr: featureJson,

        height_groupList: height_groupData,
        height_groupArr: height_groupStr,

        role_typeList: role_typeData,
        role_typeArr: role_typeStr,

        sexList: sexData,
        sexArr: sexStr,

        shape_groupList: shape_groupData,
        shape_groupArr: shape_groupStr,

        skill_groupList1: skill_groupData1,
        skill_groupArr1: skill_groupJson1,

        skill_groupList2: skill_groupData2,
        skill_groupArr2: skill_groupJson2,
        // skill_group: data.data.skill_group
      })

    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },
  /** 
    * 获取点击 年龄 字段
    */
  getAge_group: function (e) {
    var itemIndex = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + itemIndex);
    console.log("index====" + item);
    this.setData({
      currentItemAge_group: itemIndex,
      age_groupKey: this.data.age_groupList[itemIndex],
    })
    console.log("获取点击 年龄 字段" + this.data.age_groupKey);
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].age_group = parseInt(this.data.age_groupKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 年龄 字段=itemsRoles=" + JSON.stringify(this.data.itemsRoles));
  },
  /**
  * 获取点击 颜值 字段
  */
  getFace_group: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + index);
    console.log("index====" + item);
    that.setData({
      currentItemFace_group: index,
      face_groupKey: that.data.face_groupList[index],
    })
    console.log("获取点击 颜值 字段" + that.data.face_groupKey)
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].face_group = parseInt(this.data.face_groupKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 颜值 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },
  /**
 * 获取点击 特长 字段
 */
  getFeature_group: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);

    var feature_groupShenGao = that.data.feature_groupArr;
    var size = that.data.feature_groupSize;
    if (feature_groupShenGao[index].checked) {
      size--;
      feature_groupShenGao[index].checked = false;
    } else {
      if (size <= 5) {
        size++;
        feature_groupShenGao[index].checked = true;
      } else {
        wx.showModal({
          title: '提示',
          content: '亲~标签不能超过5个哟',
          showCancel: false, //不显示取消按钮
          confirmText: '确定'
        })
      }
    }
    that.setData({
      feature_groupArr: feature_groupShenGao,
      feature_groupSize: size,
    })
    var techang = [];
    for (var i = 0; i < that.data.feature_groupArr.length; i++) {
      if (that.data.feature_groupArr[i].checked) {
        techang.push(parseInt(that.data.feature_groupArr[i].val));
      }
    }
    console.log("特长传递参数=======" + JSON.stringify(techang));

    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].feature_group = JSON.stringify(techang);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 特长 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },
  /**
* 获取点击 身高 字段
*/
  getHeight_group: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + index);
    console.log("index====" + item);
    that.setData({
      currentItemHeight_group: index,
      height_groupKey: that.data.height_groupList[index],
    })
    console.log("获取点击 身高 字段" + that.data.height_groupKey)
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].height_group = parseInt(this.data.height_groupKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 身高 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },
  /**
* 获取点击 角色类型 字段
*/
  getRole_type: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + index);
    console.log("index====" + item);
    that.setData({
      currentItemRole_type: index,
      role_typeKey: that.data.role_typeList[index],
    })
    console.log("获取点击 角色类型 字段" + that.data.role_typeKey)
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].role_type = parseInt(this.data.role_typeKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 角色类型 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },
  //   /**
  // * 获取点击 角色性别 字段
  // */
  //   getSex: function (e) {
  //     var that = this;
  //     var index = parseInt(e.currentTarget.dataset.index);

  //     that.setData({
  //       currentItemSex: index,
  //       sexKey: that.data.sex[index],
  //     })
  //     console.log("获取点击 角色性别 字段====" + that.data.sexKey)

  //   },
  /**
* 获取点击 体型 字段
*/
  getShape_group: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + index);
    console.log("index====" + item);
    that.setData({
      currentItemShape_group: index,
      shape_groupKey: that.data.shape_groupList[index],
    })
    console.log("获取点击 体型 字段" + that.data.shape_groupKey)
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].shape_group = parseInt(this.data.shape_groupKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 体型 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },
  /**
* 获取点击 特征 字段
*/
  getSkill_group1: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);

    var skill_groupShenGao1 = that.data.skill_groupArr1;
    var size = that.data.skill_groupSize1;

    if (skill_groupShenGao1[index].checked) {
      size--;
      skill_groupShenGao1[index].checked = false;
    } else {
      if (size <= 5) {
        size++;
        skill_groupShenGao1[index].checked = true;
      } else {
        wx.showModal({
          title: '提示',
          content: '亲~标签不能超过5个哟',
          showCancel: false, //不显示取消按钮
          confirmText: '确定'
        })
      }
    }
    that.setData({
      skill_groupArr1: skill_groupShenGao1,
      skill_groupSize1: size,
    })
    var tezheng = [];
    for (var i = 0; i < that.data.skill_groupArr1.length; i++) {
      if (that.data.skill_groupArr1[i].checked) {
        tezheng.push(parseInt(that.data.skill_groupArr1[i].val));
      }
    }
    console.log("特征传递参数=======" + JSON.stringify(tezheng));

    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].skill_group = JSON.stringify(tezheng);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 特征 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },

  getSkill_group2: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);

    var skill_groupShenGao2 = that.data.skill_groupArr2;
    var size = that.data.skill_groupSize2;

    if (skill_groupShenGao2[index].checked) {
      size--;
      skill_groupShenGao2[index].checked = false;
    } else {
      if (size <= 5) {
        size++;
        skill_groupShenGao2[index].checked = true;
      } else {
        wx.showModal({
          title: '提示',
          content: '亲~标签不能超过5个哟',
          showCancel: false, //不显示取消按钮
          confirmText: '确定'
        })
      }
    }
    that.setData({
      skill_groupArr2: skill_groupShenGao2,
      skill_groupSize2: size,
    })
    var tezheng = [];
    for (var i = 0; i < that.data.skill_groupArr2.length; i++) {
      if (that.data.skill_groupArr2[i].checked) {
        tezheng.push(parseInt(that.data.skill_groupArr2[i].val));
      }
    }
    console.log("特征传递参数=======" + JSON.stringify(tezheng));

    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].skill_group = JSON.stringify(tezheng);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 特征 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },

  /**
 * 获取点击 语言 字段
 */
  getLanguage: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);

    var languageShenGao = that.data.languageArr;
    var size = that.data.languageSize;
    if (languageShenGao[index].checked) {
      size--;
      languageShenGao[index].checked = false;
    } else {
      if (size <= 5) {
        size++;
        languageShenGao[index].checked = true;
      } else {
        wx.showModal({
          title: '提示',
          content: '亲~标签不能超过5个哟',
          showCancel: false, //不显示取消按钮
          confirmText: '确定'
        })
      }
    }
    that.setData({
      languageArr: languageShenGao,
      languageSize: size,
    })
    var yuyan = [];
    for (var i = 0; i < that.data.languageArr.length; i++) {
      if (that.data.languageArr[i].checked) {
        yuyan.push(parseInt(that.data.languageArr[i].val));
      }
    }
    console.log("语言传递参数=======" + JSON.stringify(yuyan));

    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].language = JSON.stringify(yuyan);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 语言 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },

  /**
* 获取点击 性别 字段
*/
  getSex: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var item = parseInt(e.currentTarget.id);
    console.log("itemIndex====" + index);
    console.log("index====" + item);
    that.setData({
      currentItemSex: index,
      sexKey: that.data.sexList[index],
    })
    console.log("获取点击 性别 字段" + that.data.sexKey)
    var dataList = [];
    dataList = this.data.itemsRoles;
    dataList[item].sex = parseInt(this.data.sexKey);
    this.setData({
      itemsRoles: dataList
    })
    console.log("获取点击 性别 字段=itemsRoles=" + JSON.stringify(that.data.itemsRoles));
  },

  //以下为自定义点击事件
  //输入名称 
  filmNameInput: function (e) {
    var that = this;
    that.setData({
      filmName: e.detail.value
    })
    console.log("获取点击 filmName 字段" + that.data.filmName)
  },
  addressInput: function (e) {
    var that = this;
    that.setData({
      address: e.detail.value
    })
    console.log("获取点击 address 字段" + that.data.address)
  },
  zhouqiInput: function (e) {
    var that = this;
    that.setData({
      zhouqi: e.detail.value
    })
    console.log("获取点击 zhouqi 字段" + that.data.zhouqi)
  },
  zhipianInput: function (e) {
    var that = this;
    that.setData({
      zhipian: e.detail.value
    })
    console.log("获取点击 zhipian 字段" + that.data.zhipian)
  },
  daoyanInput: function (e) {
    var that = this;
    that.setData({
      daoyan: e.detail.value
    })
    console.log("获取点击 daoyan 字段" + that.data.daoyan)
  },
  tongchouInput: function (e) {
    var that = this;
    that.setData({
      tongchou: e.detail.value
    })
    console.log("获取点击 tongchou 字段" + that.data.tongchou)
  },
  zhuliInput: function (e) {
    var that = this;
    that.setData({
      zhuli: e.detail.value
    })
    console.log("获取点击 zhuli 字段" + that.data.zhuli)
  },
  zhixingInput: function (e) {
    var that = this;
    that.setData({
      zhixing: e.detail.value
    })
    console.log("获取点击 zhixing 字段" + that.data.zhixing)
  },
  phoneInput: function (e) {
    var that = this;
    that.setData({
      phone: e.detail.value
    })
    console.log("获取点击 phone 字段" + that.data.phone)
  },
  wxStrInput: function (e) {
    var that = this;
    that.setData({
      wxStr: e.detail.value
    })
    console.log("获取点击 wxStr 字段" + that.data.wxStr)
  },
  emailInput: function (e) {
    var that = this;
    that.setData({
      email: e.detail.value
    })
    console.log("获取点击 email 字段" + that.data.email)
  },
  jianjieInput: function (e) {
    var that = this;
    that.setData({
      jianjie: e.detail.value
    })
    console.log("获取点击 jianjie 字段" + that.data.jianjie)
  },



  /**
   * 监听日期picker选择器
   */
  shangyingPickerSelected: function (e) {
    var that = this;
    that.setData({
      shangying: e.detail.value
    })
  },
  kaishiPickerSelected: function (e) {
    var that = this;
    that.setData({
      kaishi: e.detail.value
    })
  },
  jieshuPickerSelected: function (e) {
    var that = this;
    that.setData({
      jieshu: e.detail.value
    })
  },

  //点击影片题材标签
  getYptc: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);

    that.setData({
      currentItemYptc: index,
      yptcKey: that.data.yptcList[index],
    })
    console.log("获取点击 影片题材 标签" + that.data.yptcKey)
  },
  //播出平台
  getBcpt: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);

    that.setData({
      currentItemBcpt: index,
      bcptKey: that.data.bcptList[index],
    })
    console.log("获取点击 播出平台 标签" + that.data.bcptKey)
  },
  //图片上传
  uploadImg: function (e) {
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9  
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有  
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有  
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
        var tempFilePaths = res.tempFilePaths;
        console.log('图片路径' + tempFilePaths[0]);
        wx.uploadFile({
          url: 'https://www.sc-xhzt.com/api/image/upload',
          filePath: tempFilePaths[0],
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data",
            'accept': 'application/json',
          },
          formData: {
            'file': tempFilePaths[0],
            'uid': 1,
          },
          success: function (res) {
            let json = res.data.trim();
            let arr = JSON.parse(json);
            that.setData({
              headerImg: arr.data.url,
            })
          },
          fail: function (res) {
            console.log('上传失败' + res.data);
            wx.showToast({
              title: '上传失败',
              icon: 'success',
              duration: 1200
            })
          },
        })
      }
    })
  },
  //图片上传1
  uploadImg1: function (e) {
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9  
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有  
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有  
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
        var tempFilePaths = res.tempFilePaths;
        console.log('图片路径' + tempFilePaths[0]);
        wx.uploadFile({
          url: 'https://www.sc-xhzt.com/api/image/upload',
          filePath: tempFilePaths[0],
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data",
            'accept': 'application/json',
          },
          formData: {
            'file': tempFilePaths[0],
            'uid': 1,
          },
          success: function (res) {
            let json = res.data.trim();
            let arr = JSON.parse(json);
            that.setData({
              bgImg: arr.data.url,
            })
          },
          fail: function (res) {
            console.log('上传失败' + res.data);
            wx.showToast({
              title: '上传失败',
              icon: 'success',
              duration: 1200
            })
          },
        })
      }
    })
  },

  //角色姓名 
  juesemingInput: function (e) {
    var that = this;
    var index = e.currentTarget.id;
    that.setData({
      juesemingStr: e.detail.value
    })
    var dataList = [];
    dataList = that.data.itemsRoles;
    // console.log('dataList[index]' + JSON.stringify(dataList[index]));
    dataList[index].name = that.data.juesemingStr;
    that.setData({
      itemsRoles: dataList
    })
    console.log('itemsRoles]' + JSON.stringify(that.data.itemsRoles));
  },
  //人物传记 
  zhuanjiInput: function (e) {
    var that = this;
    var index = e.currentTarget.id;
    that.setData({
      zhuanjiStr: e.detail.value
    })
    var dataList = [];
    dataList = that.data.itemsRoles;
    dataList[index].biography = that.data.zhuanjiStr;
    that.setData({
      itemsRoles: dataList
    })
    console.log('itemsRoles]' + JSON.stringify(that.data.itemsRoles));
  },

  jueseInput: function (e) {
    var that = this;
    that.setData({
      jueseStr: e.detail.value
    })
  },
  nianlingInput: function (e) {
    var that = this;
    that.setData({
      nianlingStr: e.detail.value
    })
  },
  addRole: function (e) {
    var that = this;
    var list = [];
    var imageitem;
    var imageitemstring = '';
    list = that.data.itemsRoles;
    imageitem = '{' + '"id":"' + '' + '",' +
      '"name":"' + '' + '",' +
      '"role_type":' + null + ',' +
      '"age_group":' + null + ',' +
      '"face_group":' + null + ',' +
      '"feature_group":' + null + ',' +
      '"sex":' + 1 + ',' +
      '"biography":"' + '' + '",' +
      '"others":"' + '' + '",' +
      '"height_group":' + null + ',' +
      '"shape_group":' + null + ',' +
      '"skill_group":' + null + ',' +
      '"language":' + null + '}';
    console.log("imageitem===111=" + imageitem)
    var itemsRolesList = [];
    itemsRolesList = that.data.itemsRoles;
    itemsRolesList.push(JSON.parse(imageitem));
    imageitemstring = JSON.stringify(itemsRolesList);
    var imageList = '{"roles":' + imageitemstring + '}';
    that.setData({
      itemsRoles: JSON.parse(imageList).roles,
    })
    imageList.splice
    console.log('itemsRoles==all==' + JSON.stringify(that.data.itemsRoles))
  },
  delRole: function (e) {
    var that = this;
    var index = -1;
    var itemId = e.currentTarget.dataset.id;
    var list = [];
    var list1 = [];
    list = that.data.itemsRoles;
    if (list.length > 1) {
      wx.showModal({
        title: '删除角色',
        content: '是否删除该角色？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            for (var i = 0; i < list.length; i++) {
              if (itemId == list[i].id) {
                index = i;
                if (index != -1) {
                  list.splice(index, 1);
                }
                that.setData({
                  itemsRoles: list,
                })
                console.log('删除成功============' + that.data.itemsRoles)
                break;
              }
            }
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.showModal({
        title: '操作失败',
        content: '至少需要一个角色',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
  postFilm: function (e) {
    var that = this;
    var param = {};
    if (that.data.fid != "") {
      param.fid = that.data.fid;
    }
    // if (that.data.filmName != "" && that.data.address != ""
    //   && that.data.zhouqi != "" && that.data.zhipian != ""
    //   && that.data.daoyan != "" && that.data.tongchou != ""
    //   && that.data.zhuli != "" && that.data.zhixing != ""
    //   && that.data.phone != "" && that.data.wxStr != ""
    //   && that.data.email != "" && that.data.shangying != ""
    //   && that.data.kaishi != "" && that.data.jieshu != ""
    //   && that.data.jianjie != "" && that.data.dylxKey != ""
    //   && that.data.bcptKey != "" && that.data.headerImg != ""
    // && that.data.yptcKey != ""  ) {
    param.name = that.data.filmName;
    param.headimg = that.data.headerImg;
    param.bgimg = that.data.bgImg;
    param.shoot_place = that.data.address;
    param.shoot_days = that.data.zhouqi;
    param.producer = that.data.zhipian;
    param.director = that.data.daoyan;
    param.actor_whole = that.data.tongchou;
    param.actor_assist = that.data.zhuli;
    param.deputy_director = that.data.zhixing;
    param.contact_mobile = that.data.phone;
    param.contact_wx = that.data.wxStr;
    param.contact_email = that.data.email;
    param.boot_date = that.data.shangying;
    param.begin_date = that.data.kaishi;
    param.end_date = that.data.jieshu;
    param.story_desc = that.data.jianjie;
    param.publisher_uid = that.data.uid;
    param.uid = that.data.uid;
    // param.fid = that.data.fid;
    param.subject = parseInt(that.data.yptcKey);
    param.play_platform = parseInt(that.data.bcptKey);
    param.roles = JSON.stringify(that.data.itemsRoles);
    post("/film/create", param).then(data => {
      console.log('发布剧组====================' + JSON.stringify(data.data));
      if (data.code == 0) {
        wx.showModal({
          title: '发布成功',
          content: '新剧发布成功，点击确定前往查看',
          success: function (res) {
            if (res.confirm) {//data.data
              wx.navigateBack({
                delta: -1
              });
              wx.navigateTo({
                url: '../moviedetial/moviedetial?Uid=' + that.data.uid + '&Fid=' + data.data.fid,
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      } else {
        wx.showModal({
          title: '发布失败',
          content: data.msg,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    })
    // }
  }
})

